#!/bin/sh

DVM_PATH=/home/dvmuser1/DVM/dvm_open_mpi/dvm_sys/dvm_sys
CUDA_PATH=/common/cuda
#DVM_PATH=/home/dvmuser/dvm_407_pg/dvm_sys
NAME=$1

cd src && \
make -f makefile.local && \
cd .. && \
/common/pgi/linux86-64/2011/bin/pgfortran -Mcuda=3.2 -O3 -ta=nvidia:keepgpu,cc20 ${NAME}_cuda_kernels.cuf -c && \
( echo '#include "pgi_cuda_runtime.h"' && \
grep -v "#include " <${NAME}_cuda_kernels.001.gpu && \
echo "" && \
cat ${NAME}_cuda_handlers.cu ) >${NAME}_cuda.cu && \
/common/cuda.orig/bin/nvcc --keep -arch=sm_20 -O3 -c ${NAME}_cuda.cu && \
mpif90 -free $NAME.f ${NAME}_cuda.o $DVM_PATH/lib/dvm.a dvmh.a -L$CUDA_PATH/lib64 -lcudart -o $NAME
